/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2016-2026 hmc,Inc.All Rights Reserved.
 */
package com.sys.midware.zookeeper.config;

import com.sys.midware.config.core.ConfigContainer;
import com.sys.midware.config.core.ConfigKey;
import com.sys.midware.logger.Logger;
import com.sys.midware.logger.LoggerFactory;

/**
 * 
 * <b>ClassName：</b> ConfigMongoUtil <br/>
 * <b>Description：</b> 获取配置信息工具类 <br/>
 * <b>@author：</b> mobing <br/>
 * <b>@date：</b> 2015年10月19日 下午2:55:02 <br/>
 * <b>@version: </b> <br/>
 */
public class ZKConfigUtil {
    private static final Logger logger = LoggerFactory.getLogger(ZKConfigUtil.class);

    /**
     * ConfigContainer instance
     */
    private static ConfigContainer cfg = ConfigContainer.getInstance(ConfigKey.ConfigFile.CONFIG_FILE_ROOT);


   private static boolean initFlag;
    
    public static void initConfig() {
        if(initFlag){
            return ;
        }
        ZKConfig mc = new ZKConfig();
        mc.setServerLists(cfg.getParamString(ZKConfigKey.KEY_SERVERLISTS));
        mc.setConnectionTimeoutMilliseconds(cfg.getParamInteger(ZKConfigKey.KEY_CONNECTIONTIMEOUTMILLISECONDS));
        mc.setSessionTimeoutMilliseconds(cfg.getParamInteger(ZKConfigKey.KEY_SESSIONTIMEOUTMILLISECONDS));
        mc.setDigest(cfg.getParamString(ZKConfigKey.KEY_DIGEST));
//        mc.setNameSpace(cfg.getParamString(ZKConfigKey.KEY_NAMESPACE));
        mc.setBaseSleepTimeMilliseconds(cfg.getParamInteger(ZKConfigKey.KEY_BASESLEEPTIMEMILLISECONDS));
        mc.setMaxRetries(cfg.getParamInteger(ZKConfigKey.KEY_MAXRETRIES));
        mc.setMaxSleepTimeMilliseconds(cfg.getParamInteger(ZKConfigKey.KEY_MAXSLEEPTIMEMILLISECONDS));
        ZKConfigHolder.put(mc);
        initFlag = true;
        logger.info("init config finish!");
    }
    
    
  

}
